<?php

require_once "config.php";
require_once "pastelog.controller.php";

$pastelog = new PasteLogController();

function arg($int)
{
    $args = explode('/', $_GET['q']);
    
    return $args[$int];
}

function url($uri)
{
    if (CLEAN_URL)
        return 'http://'.$_SERVER['HTTP_HOST'].
            dirname($_SERVER["SCRIPT_NAME"]).'/'.$uri;
    else
        return 'http://'.$_SERVER['HTTP_HOST'].
            dirname($_SERVER["SCRIPT_NAME"]).'/?q='.$uri;
}

function my_smarty_url($params, &$smarty)
{
    return url($params['uri']);
}

$arg = arg(0);

if ($_POST['action'] == 'savePaste') {
    $pastelog->savePaste();
} elseif (is_numeric($arg)) {
    $pastelog->displayPaste($arg);
} elseif ($arg == 'about') {
    $pastelog->displayAbout();
} elseif ($arg == 'captcha') {
    $pastelog->displayCaptcha();
} elseif ($arg == 'download' && is_numeric(arg(1))) {
    $pastelog->downloadPaste(arg(1));
} else {
    $pastelog->displayNew();
}

?>
